package ren.kane.phoenix.util.io;

import java.io.CharArrayReader;
import java.io.IOException;

/**
 * @author renrk(1275) on 2019-08-12 5:22 PM
 **/
public class CharArrayReaderTest {

    private static final int LEN = 5;
    private static final char[] ARRAY_LETTERS = new char[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    private static void testCharArrayReader() {
        try {
            CharArrayReader charArrayReader = new CharArrayReader(ARRAY_LETTERS);
            for (int i = 0; i < LEN; i++) {
                if (charArrayReader.ready()) {
                    char tmp = (char) charArrayReader.read();
                    System.out.printf("%d : %c\n", i, tmp);
                }
            }
            if (!charArrayReader.markSupported()) {
                System.out.println("make not supported!");
                return;
            }
            charArrayReader.mark(0);
            charArrayReader.skip(5);
            char[] buf = new char[LEN];
            charArrayReader.read(buf, 0, LEN);
            System.out.printf("buf=%s\n", String.valueOf(buf));
            charArrayReader.reset();
            charArrayReader.read(buf, 0, LEN);
            System.out.printf("buf=%s\n", String.valueOf(buf));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testCharArrayReader();
    }
}
